package cn.loan.service.impl;

import cn.loan.dao.UserMapper;
import cn.loan.entity.User;
import cn.loan.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Timestamp;
import java.text.DecimalFormat;
import java.util.Random;

/**
 * @Author: 毛苏宇
 * @Description: You can do it!
 * @Date: Create in 10:52 2019/3/20
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;


    @Override
    public User login(User user) {
        return userMapper.findUser(user);
    }


    @Override
    public boolean userNumIsExits(String userNum) {
        return userMapper.findUserNumIsExist(userNum) > 0 ? true : false;
    }


    @Override
    public boolean modifyPwd(User user) {
        return userMapper.updatePwd(user) > 0 ? true : false;
    }


    @Override
    public boolean register(User user) {
        //user.setCode();
        user.setRegister_time(new Timestamp(System.currentTimeMillis()));   //当前时间
        return userMapper.addUser(user) > 0 ? true : false;
    }


    @Override
    public boolean findCode(String code) {
        return userMapper.findUserCode(code) > 0 ? true : false;
    }


    @Override
    public User getMyInfo(int userId) {
        return userMapper.findMyInfo(userId);
    }


    @Override
    public boolean getIsPayment(int user_id) {
        return userMapper.findIsPayment(user_id) > 0 ? true : false;
    }


}
